package com.autonavi.yunda.yunji.configuration;

import com.autonavi.yunda.yunji.common.exception.AmapExceptionCode;
import com.autonavi.yunda.yunji.common.web.entity.GlobalResponse;
import com.autonavi.yunda.yunji.configuration.exception.ResourceNotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author cizhong.wcs
 * @date 2022/1/29 11:14 上午
 */
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class EngineWebExceptionHandler {
    @ExceptionHandler(ResourceNotFoundException.class)
    @ResponseStatus(value = HttpStatus.NOT_FOUND)
    public GlobalResponse<String> notFound(HttpServletRequest request, HttpServletResponse response) {
        GlobalResponse<String> result = new GlobalResponse<>();
        result.setCode(AmapExceptionCode.COMMON_RESOURCE_NOT_FOUNT.getCode());
        result.setMessage(AmapExceptionCode.COMMON_RESOURCE_NOT_FOUNT.getText());
        return result;
    }
}
